﻿<shared:WindowBase x:Class="Bymed.SpineScan.WPF.SingleTestDetailWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:userControl="clr-namespace:Bymed.SpineScan.WPF.CustomizedUserControl"
        xmlns:shared="clr-namespace:Bymed.SpineScan.WPF.Shared"
        Title="单项测试结果" Height="750" Width="1200" 
        WindowStartupLocation="CenterScreen" 
        DataContext="{Binding SingleTestDetail, Source={StaticResource Locator}}">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Skins/MainSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Window.Background>
        <ImageBrush ImageSource="/Skins/Resource/Image/MainWindowBackground.png"/>
    </Window.Background>
    <Grid Height="720">
        <Grid.RowDefinitions>
            <!-- Patient Info & Selected Test Items -->
            <RowDefinition />
            <!-- Navigation Buttons -->
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid>
            <Grid.Background>
                <ImageBrush ImageSource="/Skins/Resource/Image/GrayRightAboveTabBackground.png" />
            </Grid.Background>
            <Grid.RowDefinitions>
                <!-- Page Title -->
                <RowDefinition Height="40" />
                <!-- Main Content -->
                <RowDefinition />
            </Grid.RowDefinitions>
            <TextBlock Margin="0,0,15,-5" Text="单项测试结果" Foreground="#153364" FontSize="26" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
            <Grid Grid.Row="1" Margin="0,20,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="260" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <userControl:PatientBasicInfoDisplayUserControl DataContext="{Binding PatientBasicInfoDisplayViewModel}" 
                   HorizontalAlignment="Right" Width="229" Height="535" VerticalAlignment="Top" />
                <Grid Grid.Column="1">
                    <Grid.RowDefinitions>
                        <!-- Current Test Result -->
                        <RowDefinition Height="Auto" />
                        <!-- History Analysis Chart -->
                        <RowDefinition Height="Auto" />
                        <!-- History Data List -->
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <!-- Current Test Result -->
                    <StackPanel>
                        <StackPanel.Style>
                            <Style TargetType="{x:Type StackPanel}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsCustomizedTestItem}" Value="True">
                                        <Setter Property="Visibility" Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </StackPanel.Style>
                        <TextBlock Margin="0,0,0,6" HorizontalAlignment="Center">
                            <TextBlock.Style>
                                <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource InfoTextBlock}">
                                    <Setter Property="Text" Value="{Binding SelectedItem.TestDateDisplay, ElementName=HistoryDataGrid}" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding SelectedItem, ElementName=HistoryDataGrid}" Value="{x:Null}">
                                            <Setter Property="Text" Value="本次测量" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                        </TextBlock>
                        <userControl:TestResultRegularChartUserControl DataContext="{Binding SelectedTestItem}" Width="720" />
                        <userControl:TrendChartUserControl DataContext="{Binding SelectedTestItem}" Width="750">
                            <userControl:TrendChartUserControl.Style>
                                <Style TargetType="{x:Type UserControl}">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding TestItemName}" Value="ScoliosisATI">
                                            <Setter Property="Visibility" Value="Visible" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </userControl:TrendChartUserControl.Style>
                        </userControl:TrendChartUserControl>
                    </StackPanel>
                    <!-- History Analysis Chart -->
                    <StackPanel Grid.Row="1" Margin="0,6,0,0" Width="730">
                        <StackPanel.Style>
                            <Style TargetType="{x:Type StackPanel}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsCustomizedTestItem}" Value="True">
                                        <Setter Property="Visibility" Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </StackPanel.Style>
                        <TextBlock Text="历史分析" HorizontalAlignment="Center" Style="{StaticResource InfoTextBlock}" />
                        <ListBox BorderThickness="0" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ItemsSource="{Binding HistoryAnalysisChartSource}">
                            <ListBox.Style>
                                <Style TargetType="{x:Type ListBox}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding HistoryAnalysisChartSource.Count}" Value="0">
                                            <Setter Property="Visibility" Value="Collapsed" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </ListBox.Style>
                            <ListBox.Resources>
                                <SolidColorBrush Color="Black" x:Key="{x:Static SystemColors.HighlightTextBrushKey}" />
                                <SolidColorBrush Color="Transparent" x:Key="{x:Static SystemColors.HighlightBrushKey}" />
                                <SolidColorBrush Color="Transparent" x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" />
                            </ListBox.Resources>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <userControl:TestResultRegularChartUserControl Margin="0,0,0,4" DataContext="{Binding}" Width="720" />
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </StackPanel>
                    <!-- History Data List -->
                    <StackPanel Grid.Row="2" Margin="0,6,0,18" VerticalAlignment="Bottom">
                        <TextBlock Text="历史数据" Margin="0,0,0,6" HorizontalAlignment="Center" Style="{StaticResource InfoTextBlock}" />
                        <DataGrid x:Name="HistoryDataGrid" ItemsSource="{Binding HistoryDataList}" Width="720" SelectionMode="Single" 
                                  SelectedItem="{Binding SelectedTestItem, Mode=OneWayToSource}" IsReadOnly="True">
                            <DataGrid.Style>
                                <Style TargetType="{x:Type DataGrid}" BasedOn="{StaticResource DataGridBase}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding IsCustomizedTestItem}" Value="True">
                                            <Setter Property="Height" Value="480" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding IsCustomizedTestItem}" Value="False">
                                            <Setter Property="Height" Value="180" />
                                        </DataTrigger>
                                        <MultiDataTrigger>
                                            <MultiDataTrigger.Conditions>
                                                <Condition Binding="{Binding IsCustomizedTestItem}" Value="False" />
                                                <Condition Binding="{Binding SelectedTestItem.TestItemName}" Value="ScoliosisATI" />
                                            </MultiDataTrigger.Conditions>
                                            <Setter Property="Height" Value="110" />
                                        </MultiDataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </DataGrid.Style>
                            <DataGrid.Resources>
                                <SolidColorBrush Color="LightBlue" x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" />
                            </DataGrid.Resources>
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="序号" Width="60" Binding="{Binding SequenceNumber}" />
                                <DataGridTextColumn Header="测试日期" Width="160" Binding="{Binding TestDateDisplay}" />
                                <DataGridTextColumn Header="测试结果" Width="*" Binding="{Binding FormattedTestResult}" />
                            </DataGrid.Columns>
                        </DataGrid>
                    </StackPanel>
                </Grid>
            </Grid>
        </Grid>
        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom">
            <Button Content="打印" Margin="0,0,120,0" Tag="/Skins/Resource/Image/Print.png" Style="{StaticResource NavigationButton}" Click="ButtonPrint_Click" />
            <Button Content="关闭" Margin="0,0,120,0" Tag="/Skins/Resource/Image/Cancel.png" Style="{StaticResource NavigationButton}" Click="ButtonClose_Click" />
        </StackPanel>
    </Grid>
</shared:WindowBase>
